<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (! defined('ROOT')) die();
class Captcha extends ParentCaptcha {
	var $image = null;
	var $font_height = 25;
	var $code = '';
	function Captcha($code){
		$this->code = $code;
		$this->image = imagecreatetruecolor($this->width,$this->height);
		$this->gen_start_image();
		imagefill($this->image,0,0,$this->white_c);
		$this->get_fonts();
		$this->type_letters();
		$this->_for();
		$this->out_img($this->wave($this->image));
	}
	function gen_start_image(){
		$this->white_c     = imagecolorallocate($this->image,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
		$this->black_c     = imagecolorallocate($this->image,mt_rand(0,50),mt_rand(0,50),mt_rand(0,50));
	}
	function type_letters(){
		$imagebox = imagettfbbox($this->font_height,0,$this->font,$this->code);
		$xpos = ceil(($this->width  - ($imagebox[0] + $imagebox[2]) )/2);
		$ypos = ceil(($this->height - ($imagebox[1] + $imagebox[7]) )/2);

		imagettftext($this->image,$this->font_height,0,$xpos,40,$this->black_c,$this->font,$this->code);
	}
	function _for(){
		$rand_x = mt_rand(10,$this->width-10);
		$rand_y = mt_rand(10,$this->height-10);
		
		$X = $this->width ;

		$br = imagecreate(2,2);
		imagesetbrush($this->image,$br);
		$tru = true;
		$mn = 0;
		for ($i = 1;$i<$X;$i++){
			if ($tru) {
				$mn ++;
				$tru = false;
			} else {
				$mn += 3;
				$tru = true;
			}
			
			imagearc($this->image,$rand_x,$rand_y,$mn,$mn,0,360,$this->white_c);
			
		}
	}
}